import { request } from '../../utils/request';
import { IPage, IPageQuery } from '../index';

export interface IEmployeeQuery extends IPageQuery {
  work?: string;

  startBirthday?: Date;

  endBirthday?: Date;

  name?: string;

  address?: string;

  id?: number;

  phone?: string;
}

export interface IEmployeeInfo {
  work: string;

  startBirthday: Date;

  endBirthday: Date;

  name: string;

  address: string;

  id: string;

  phone: string;

  sex: number;

  avatar: string;
}

export interface ITeacherInfo {
  id: string;
  name: string;
}
export const getEmployeeList = (data: IEmployeeQuery) =>
  request<IPage<IEmployeeInfo>>({
    url: '/employee/list',
    method: 'post',
    data,
  });

export const deleteEmployee = (id: number) =>
  request<boolean>({
    url: '/employee/delete',
    method: 'post',
    data: { id },
  });

export const updateEmployee = (data: IEmployeeInfo) =>
  request<boolean>({
    url: '/employee/update',
    method: 'post',
    data,
  });

export const addEmployee = (data: any) =>
  request<boolean>({
    url: '/employee/add',
    method: 'post',
    data,
  });

export const downloadEmployee = () =>
  request({
    url: '/employee/download',
    method: 'get',
    responseType: 'blob',
  }).then((response: any) => {
    const url = window.URL.createObjectURL(new Blob([response]));
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', '员工.xlsx');
    document.body.appendChild(link);
    link.click();
  });

export const getTeacherNames = (data: any) =>
  request<ITeacherInfo[]>({
    url: 'employee/names',
    method: 'post',
    data,
  });
